package com.stylefeng.guns.modular.flagglory.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.common.persistence.model.Setting;
import com.stylefeng.guns.common.persistence.dao.SettingMapper;
import com.stylefeng.guns.modular.flagglory.service.ISettingService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author stylefeng123
 * @since 2018-02-27
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SettingServiceImpl extends ServiceImpl<SettingMapper, Setting> implements ISettingService {
    public void getQuestionSetting(JSONObject data){
        EntityWrapper<Setting> settingEntityWrapper = new EntityWrapper<>();
        settingEntityWrapper.where("`key`='question_score'");
        Setting question_score = selectOne(settingEntityWrapper);
        settingEntityWrapper = new EntityWrapper<>();
        settingEntityWrapper.where("`key`='question_time_score'");
        Setting question_time_score = selectOne(settingEntityWrapper);
        settingEntityWrapper = new EntityWrapper<>();
        settingEntityWrapper.where("`key`='question_time'");
        Setting question_time = selectOne(settingEntityWrapper);
        settingEntityWrapper = new EntityWrapper<>();
        settingEntityWrapper.where("`key`='question_count'");
        Setting question_count = selectOne(settingEntityWrapper);
        data.put("questionScore",question_score);
        data.put("secondScore",question_time_score);
        data.put("questionTime",question_time);
        data.put("questionCount",question_count);
    }

    @Override
    public Setting getSetting(String key) {
        EntityWrapper<Setting> settingEntityWrapper = new EntityWrapper<>();
        settingEntityWrapper.where("`key`='" + key + "'");
        return selectOne(settingEntityWrapper);
    }
}
